@echo off
setlocal

if not exist hiredis-master (
    PowerShell -Command "Expand-Archive hiredis-master.zip ."
)
cd hiredis-master 

rem 创建输出目录
if not exist ..\lib mkdir ..\lib
if not exist ..\lib\x64 mkdir ..\lib\x64
if not exist ..\lib\Win32 mkdir ..\lib\Win32
if not exist ..\lib\x64\Debug mkdir ..\lib\x64\Debug
if not exist ..\lib\x64\Release mkdir ..\lib\x64\Release
if not exist ..\lib\Win32\Debug mkdir ..\lib\Win32\Debug
if not exist ..\lib\Win32\Release mkdir ..\lib\Win32\Release
if not exist ..\include mkdir ..\include
if not exist ..\include\hiredis mkdir ..\include\hiredis
if not exist ..\include\hiredis\adapters mkdir ..\include\hiredis\adapters

rem 清理并重建（确保获取最新头文件）
if exist ..\include\hiredis\* del /q ..\include\hiredis\*
if exist ..\include\hiredis\adapters\* del /q ..\include\hiredis\adapters\*

mkdir build64d 
cd build64d
set STAGING_DIR=".\dist"
cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=%STAGING_DIR% ..
cmake --build . --config Debug
cmake --install . --config Debug
copy ".\dist\lib\*.lib" ..\..\lib\x64\Debug
copy ".\dist\bin\*.dll" ..\..\lib\x64\Debug
robocopy .\dist\include\hiredis ..\..\include\hiredis /E /COPYALL /R:1 /W:1 /NFL /NDL
cd ..

mkdir build64r
cd build64r
set STAGING_DIR=".\dist"
cmake -G "Visual Studio 17 2022" -A x64 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=%STAGING_DIR% ..
cmake --build . --config Release
cmake --install . --config Release
copy ".\dist\lib\*.lib" ..\..\lib\x64\Release
copy ".\dist\bin\*.dll" ..\..\lib\x64\Release
cd ..

mkdir build32d
cd build32d
set STAGING_DIR=".\dist"
cmake -G "Visual Studio 17 2022" -A Win32 -DCMAKE_BUILD_TYPE=Debug -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=%STAGING_DIR% ..
cmake --build . --config Debug
cmake --install . --config Debug
copy ".\dist\lib\*.lib" ..\..\lib\Win32\Debug
copy ".\dist\bin\*.dll" ..\..\lib\Win32\Debug
cd ..

mkdir build32r
cd build32r
set STAGING_DIR=".\dist"
cmake -G "Visual Studio 17 2022" -A Win32 -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=%STAGING_DIR% ..
cmake --build . --config Release
cmake --install . --config Release
copy ".\dist\lib\*.lib" ..\..\lib\Win32\Release
copy ".\dist\bin\*.dll" ..\..\lib\Win32\Release
cd ..